{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "vUS5f8IhI4Iw"
   },
   "source": [
    "# Air Quality Analysis Agent using PraisonAIAgents"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "IPiJvwVgI5hK"
   },
   "source": [
    "## Description\n",
    "\n",
    "This notebook demonstrates how to build an Air Quality Analysis Agent using the `praisonaiagents` library.  \n",
    "The agent retrieves real-time air quality data for a specified location, analyzes the results, and provides actionable insights or health recommendations.  \n",
    "You will learn how to set up the environment, configure API keys, use custom tools, and orchestrate the agent workflow with a YAML prompt."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "oqdL8WpNTKu5"
   },
   "source": [
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/Health_Fitness_Agents/Air_Quality_Analysis_Agent.ipynb)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "p7CFp0tkJKmU"
   },
   "source": [
    "# Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "q6Aq57bqJKFc"
   },
   "outputs": [],
   "source": [
    "!pip install praisonaiagents firecrawl requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "NLJn9uGVJldu"
   },
   "source": [
    "# Set up API Key"
   ]
  },{
 "cell_type": "code",
 "execution_count": 32,
 "metadata": {
  "id": "ZxHL7mJYJpVb"
 },
 "outputs": [],
 "source": [
  "# Replace with your actual API keys\n",
  "FIRECRAWL_API_KEY = \"fc-...\"  # Your Firecrawl API key\n",
  "OPENAI_API_KEY = \"sk-...\"     # Your OpenAI API key\n",
  "\n",
  "import os\n",
  "os.environ[\"FIRECRAWL_API_KEY\"] = FIRECRAWL_API_KEY\n",
  "os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n"
 ]
},
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "eVb00IhbJ60M"
   },
   "source": [
    "# Tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "id": "3YgwDwyFLXlU"
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "from firecrawl import FirecrawlApp\n",
    "from typing import Dict\n",
    "\n",
    "class AQIDataFetcher:\n",
    "    def __init__(self, firecrawl_key: str):\n",
    "        self.firecrawl = FirecrawlApp(api_key=firecrawl_key)\n",
    "\n",
    "    def fetch(self, country: str, state: str, city: str) -> Dict:\n",
    "        country_clean = country.lower().replace(' ', '-')\n",
    "        city_clean = city.lower().replace(' ', '-')\n",
    "        if not state or state.lower() == 'none':\n",
    "            url = f\"https://www.aqi.in/dashboard/{country_clean}/{city_clean}\"\n",
    "        else:\n",
    "            state_clean = state.lower().replace(' ', '-')\n",
    "            url = f\"https://www.aqi.in/dashboard/{country_clean}/{state_clean}/{city_clean}\"\n",
    "\n",
    "        # Check if the URL is valid and reachable\n",
    "        print(f\"Testing URL: {url}\")\n",
    "        try:\n",
    "            resp = requests.get(url)\n",
    "            print(f\"Status code: {resp.status_code}\")\n",
    "            if resp.status_code != 200:\n",
    "                print(f\"URL not reachable: {url} (status code: {resp.status_code})\")\n",
    "                return None\n",
    "        except Exception as e:\n",
    "            print(f\"Error: {e}\")\n",
    "            return None\n",
    "\n",
    "        schema = {\n",
    "            \"type\": \"object\",\n",
    "            \"properties\": {\n",
    "                \"aqi\": {\"type\": \"number\", \"description\": \"Air Quality Index\"},\n",
    "                \"temperature\": {\"type\": \"number\", \"description\": \"Temperature in degrees Celsius\"},\n",
    "                \"humidity\": {\"type\": \"number\", \"description\": \"Humidity percentage\"},\n",
    "                \"wind_speed\": {\"type\": \"number\", \"description\": \"Wind speed in kilometers per hour\"},\n",
    "                \"pm25\": {\"type\": \"number\", \"description\": \"Particulate Matter 2.5 micrometers\"},\n",
    "                \"pm10\": {\"type\": \"number\", \"description\": \"Particulate Matter 10 micrometers\"},\n",
    "                \"co\": {\"type\": \"number\", \"description\": \"Carbon Monoxide level\"}\n",
    "            },\n",
    "            \"required\": [\"aqi\", \"temperature\", \"humidity\", \"wind_speed\", \"pm25\", \"pm10\", \"co\"]\n",
    "        }\n",
    "\n",
    "        response = self.firecrawl.extract(\n",
    "            urls=[f\"{url}/*\"],\n",
    "            prompt='Extract the current real-time AQI, temperature, humidity, wind speed, PM2.5, PM10, and CO levels from the page. Also extract the timestamp of the data.',\n",
    "            schema=schema\n",
    "        )\n",
    "        return response"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3sUNJChKOVUm"
   },
   "source": [
    "# YAML Prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "0G9tLj0nJ8B_",
    "outputId": "61e66fe7-df17-4d2d-ad27-a9f4466298a4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'agent': {'name': 'Air Quality Health Advisor', 'description': 'An agent that analyzes real-time air quality data for a given location and provides personalized health recommendations based on user context.\\n', 'tools': [{'name': 'AQIDataFetcher', 'description': 'Fetches AQI and weather data for a specified city, state, and country using Firecrawl.'}], 'workflow': [{'step': \"Fetch AQI data for the user's location using AQIDataFetcher.\"}, {'step': 'Analyze AQI and weather data.'}, {'step': \"Consider user's medical conditions and planned activity.\"}, {'step': 'Generate health and activity recommendations.'}]}, 'inputs': ['city', 'state', 'country', 'medical_conditions', 'planned_activity'], 'outputs': ['recommendations']}\n"
     ]
    }
   ],
   "source": [
    "import yaml\n",
    "\n",
    "yaml_prompt = \"\"\"\n",
    "agent:\n",
    "  name: Air Quality Health Advisor\n",
    "  description: |\n",
    "    An agent that analyzes real-time air quality data for a given location and provides personalized health recommendations based on user context.\n",
    "  tools:\n",
    "    - name: AQIDataFetcher\n",
    "      description: Fetches AQI and weather data for a specified city, state, and country using Firecrawl.\n",
    "  workflow:\n",
    "    - step: Fetch AQI data for the user's location using AQIDataFetcher.\n",
    "    - step: Analyze AQI and weather data.\n",
    "    - step: Consider user's medical conditions and planned activity.\n",
    "    - step: Generate health and activity recommendations.\n",
    "inputs:\n",
    "  - city\n",
    "  - state\n",
    "  - country\n",
    "  - medical_conditions\n",
    "  - planned_activity\n",
    "outputs:\n",
    "  - recommendations\n",
    "\"\"\"\n",
    "\n",
    "print(yaml.safe_load(yaml_prompt))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "2HIPkoUyKEY-"
   },
   "source": [
    "# Main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000,
     "referenced_widgets": [
      "4c2bac52ad444499b362978d8fe92d97",
      "5203e4d9bd3c47f09d2f204c7f1e078f"
     ]
    },
    "id": "UQ4sHVW0KFp-",
    "outputId": "4efe39ea-c924-41e9-cc66-f4894e367280"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Testing URL: https://www.aqi.in/dashboard/india/maharashtra/mumbai\n",
      "Status code: 200\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╭─ </span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8; font-weight: bold\">Agent Info</span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\"> ────────────────────────────────────────────────────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #ff9b9b; text-decoration-color: #ff9b9b; font-weight: bold\">👤 Agent:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Air Quality Health Advisor</span>                                                                           <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #b4b4b3; text-decoration-color: #b4b4b3; font-weight: bold\">Role:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Assistant</span>                                                                                                <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[38;2;210;227;200m╭─\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[1;38;2;210;227;200mAgent Info\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[38;2;210;227;200m───────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;210;227;200m─╮\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;255;155;155m👤 Agent:\u001b[0m \u001b[38;2;255;229;229mAir Quality Health Advisor\u001b[0m                                                                           \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;180;180;179mRole:\u001b[0m \u001b[38;2;255;229;229mAssistant\u001b[0m                                                                                                \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4c2bac52ad444499b362978d8fe92d97",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">Response generated in 10.8s</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2mResponse generated in 10.8s\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭───────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> You are an expert health advisor using the gpt-5-nano Mini model.                                                   <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">Based on the following air quality conditions in Mumbai, Maharashtra, India:</span><span style=\"background-color: #272822\">                                  </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Overall AQI: 75</span><span style=\"background-color: #272822\">                                                                                             </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- PM2.5 Level: 22 µg/m³</span><span style=\"background-color: #272822\">                                                                                       </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- PM10 Level: 60 µg/m³</span><span style=\"background-color: #272822\">                                                                                        </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- CO Level: 650 ppb</span><span style=\"background-color: #272822\">                                                                                           </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">Weather conditions:</span><span style=\"background-color: #272822\">                                                                                           </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Temperature: 28°C</span><span style=\"background-color: #272822\">                                                                                           </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Humidity: 84%</span><span style=\"background-color: #272822\">                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Wind Speed: 30 km/h</span><span style=\"background-color: #272822\">                                                                                         </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">User's Context:</span><span style=\"background-color: #272822\">                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Medical Conditions: asthma</span><span style=\"background-color: #272822\">                                                                                  </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">- Planned Activity: morning jog for 2 hours</span><span style=\"background-color: #272822\">                                                                   </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">**Comprehensive Health Recommendations:**</span><span style=\"background-color: #272822\">                                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">1. **Impact of Current Air Quality on Health:**</span><span style=\"background-color: #272822\">                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">2. **Necessary Safety Precautions for Planned Activity:**</span><span style=\"background-color: #272822\">                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">3. **Advisability of Planned Activity:**</span><span style=\"background-color: #272822\">                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">4. **Best Time to Conduct the Activity:**</span><span style=\"background-color: #272822\">                                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m────────────────────────────────────────────────────\u001b[0m\u001b[36m Task \u001b[0m\u001b[36m─────────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m You are an expert health advisor using the gpt-5-nano Mini model.                                                   \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mBased on the following air quality conditions in Mumbai, Maharashtra, India:\u001b[0m\u001b[48;2;39;40;34m                                 \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Overall AQI: 75\u001b[0m\u001b[48;2;39;40;34m                                                                                            \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- PM2.5 Level: 22 µg/m³\u001b[0m\u001b[48;2;39;40;34m                                                                                      \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- PM10 Level: 60 µg/m³\u001b[0m\u001b[48;2;39;40;34m                                                                                       \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- CO Level: 650 ppb\u001b[0m\u001b[48;2;39;40;34m                                                                                          \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[48;2;39;40;34m                                                                                                             \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mWeather conditions:\u001b[0m\u001b[48;2;39;40;34m                                                                                          \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Temperature: 28°C\u001b[0m\u001b[48;2;39;40;34m                                                                                          \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Humidity: 84%\u001b[0m\u001b[48;2;39;40;34m                                                                                              \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Wind Speed: 30 km/h\u001b[0m\u001b[48;2;39;40;34m                                                                                        \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[48;2;39;40;34m                                                                                                             \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mUser's Context:\u001b[0m\u001b[48;2;39;40;34m                                                                                              \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Medical Conditions: asthma\u001b[0m\u001b[48;2;39;40;34m                                                                                 \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m- Planned Activity: morning jog for 2 hours\u001b[0m\u001b[48;2;39;40;34m                                                                  \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[48;2;39;40;34m                                                                                                             \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m**Comprehensive Health Recommendations:**\u001b[0m\u001b[48;2;39;40;34m                                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m1. **Impact of Current Air Quality on Health:**\u001b[0m\u001b[48;2;39;40;34m                                                              \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m2. **Necessary Safety Precautions for Planned Activity:**\u001b[0m\u001b[48;2;39;40;34m                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m3. **Advisability of Planned Activity:**\u001b[0m\u001b[48;2;39;40;34m                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m4. **Best Time to Conduct the Activity:**\u001b[0m\u001b[48;2;39;40;34m                                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭─────────────────────────────────────────────────── Response ────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> Certainly! Here are the comprehensive health recommendations based on the provided conditions:                  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 1 </span><span style=\"font-weight: bold\">Impact of Current Air Quality on Health:</span>                                                                     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>The overall AQI of 75 is considered \"Moderate.\" This level is generally acceptable for most individuals,  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>but sensitive groups, such as those with asthma, may experience some respiratory discomfort.              <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>PM2.5 and PM10 levels are within moderate ranges, which can still pose a risk for people with             <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>pre-existing respiratory conditions like asthma.                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>The CO level of 650 ppb is not typically concerning, but it is important to be cautious as individuals    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>with asthma may be more sensitive to pollutants.                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 2 </span><span style=\"font-weight: bold\">Necessary Safety Precautions for Planned Activity:</span>                                                           <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Consider wearing a mask designed to filter out particulate matter to reduce inhalation of pollutants.     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Carry a rescue inhaler and any other prescribed asthma medication.                                        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Stay hydrated, as high humidity can exacerbate asthma symptoms.                                           <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Monitor your breathing and be prepared to stop the activity if you experience any respiratory distress.   <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Choose a route with less traffic to minimize exposure to vehicle emissions.                               <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 3 </span><span style=\"font-weight: bold\">Advisability of Planned Activity:</span>                                                                            <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Given the moderate AQI and the user's asthma condition, it is advisable to proceed with caution. A 2-hour <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>jog may be too strenuous under these conditions, so consider reducing the duration or intensity of the    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>jog.                                                                                                      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>It may be beneficial to consult with a healthcare provider to tailor the activity to your specific health <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>needs.                                                                                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 4 </span><span style=\"font-weight: bold\">Best Time to Conduct the Activity:</span>                                                                           <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Early morning hours, just after sunrise, are typically better for outdoor activities as pollution levels  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>tend to be lower.                                                                                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Avoid peak traffic times to reduce exposure to vehicle emissions.                                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Check real-time air quality updates to ensure conditions remain stable or improve before starting the     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>activity.                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> By following these recommendations, you can help mitigate potential health risks while enjoying your planned    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> activity.                                                                                                       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m──────────────────────────────────────────────────\u001b[0m\u001b[36m Response \u001b[0m\u001b[36m───────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m Certainly! Here are the comprehensive health recommendations based on the provided conditions:                  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 1 \u001b[0m\u001b[1mImpact of Current Air Quality on Health:\u001b[0m                                                                     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mThe overall AQI of 75 is considered \"Moderate.\" This level is generally acceptable for most individuals,  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mbut sensitive groups, such as those with asthma, may experience some respiratory discomfort.              \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mPM2.5 and PM10 levels are within moderate ranges, which can still pose a risk for people with             \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mpre-existing respiratory conditions like asthma.                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mThe CO level of 650 ppb is not typically concerning, but it is important to be cautious as individuals    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mwith asthma may be more sensitive to pollutants.                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 2 \u001b[0m\u001b[1mNecessary Safety Precautions for Planned Activity:\u001b[0m                                                           \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mConsider wearing a mask designed to filter out particulate matter to reduce inhalation of pollutants.     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mCarry a rescue inhaler and any other prescribed asthma medication.                                        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mStay hydrated, as high humidity can exacerbate asthma symptoms.                                           \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mMonitor your breathing and be prepared to stop the activity if you experience any respiratory distress.   \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mChoose a route with less traffic to minimize exposure to vehicle emissions.                               \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 3 \u001b[0m\u001b[1mAdvisability of Planned Activity:\u001b[0m                                                                            \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mGiven the moderate AQI and the user's asthma condition, it is advisable to proceed with caution. A 2-hour \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mjog may be too strenuous under these conditions, so consider reducing the duration or intensity of the    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mjog.                                                                                                      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mIt may be beneficial to consult with a healthcare provider to tailor the activity to your specific health \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mneeds.                                                                                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 4 \u001b[0m\u001b[1mBest Time to Conduct the Activity:\u001b[0m                                                                           \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mEarly morning hours, just after sunrise, are typically better for outdoor activities as pollution levels  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mtend to be lower.                                                                                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mAvoid peak traffic times to reduce exposure to vehicle emissions.                                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mCheck real-time air quality updates to ensure conditions remain stable or improve before starting the     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mactivity.                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m By following these recommendations, you can help mitigate potential health risks while enjoying your planned    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m activity.                                                                                                       \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=== Air Quality Analysis Agent Recommendations ===\n",
      "Certainly! Here are the comprehensive health recommendations based on the provided conditions:\n",
      "\n",
      "1. **Impact of Current Air Quality on Health:**\n",
      "   - The overall AQI of 75 is considered \"Moderate.\" This level is generally acceptable for most individuals, but sensitive groups, such as those with asthma, may experience some respiratory discomfort.\n",
      "   - PM2.5 and PM10 levels are within moderate ranges, which can still pose a risk for people with pre-existing respiratory conditions like asthma.\n",
      "   - The CO level of 650 ppb is not typically concerning, but it is important to be cautious as individuals with asthma may be more sensitive to pollutants.\n",
      "\n",
      "2. **Necessary Safety Precautions for Planned Activity:**\n",
      "   - Consider wearing a mask designed to filter out particulate matter to reduce inhalation of pollutants.\n",
      "   - Carry a rescue inhaler and any other prescribed asthma medication.\n",
      "   - Stay hydrated, as high humidity can exacerbate asthma symptoms.\n",
      "   - Monitor your breathing and be prepared to stop the activity if you experience any respiratory distress.\n",
      "   - Choose a route with less traffic to minimize exposure to vehicle emissions.\n",
      "\n",
      "3. **Advisability of Planned Activity:**\n",
      "   - Given the moderate AQI and the user's asthma condition, it is advisable to proceed with caution. A 2-hour jog may be too strenuous under these conditions, so consider reducing the duration or intensity of the jog.\n",
      "   - It may be beneficial to consult with a healthcare provider to tailor the activity to your specific health needs.\n",
      "\n",
      "4. **Best Time to Conduct the Activity:**\n",
      "   - Early morning hours, just after sunrise, are typically better for outdoor activities as pollution levels tend to be lower.\n",
      "   - Avoid peak traffic times to reduce exposure to vehicle emissions.\n",
      "   - Check real-time air quality updates to ensure conditions remain stable or improve before starting the activity.\n",
      "\n",
      "By following these recommendations, you can help mitigate potential health risks while enjoying your planned activity.\n"
     ]
    }
   ],
   "source": [
    "from praisonaiagents import Agent\n",
    "import os\n",
    "\n",
    "# User input (you can change these for other locations)\n",
    "user_city = \"Mumbai\"\n",
    "user_state = \"Maharashtra\"\n",
    "user_country = \"India\"\n",
    "user_medical_conditions = \"asthma\"\n",
    "user_planned_activity = \"morning jog for 2 hours\"\n",
    "\n",
    "aqi_fetcher = AQIDataFetcher(firecrawl_key=os.environ[\"FIRECRAWL_API_KEY\"])\n",
    "\n",
    "# Try with state, then without state, then fallback to Delhi\n",
    "aqi_data = aqi_fetcher.fetch(\n",
    "    country=user_country,\n",
    "    state=user_state,\n",
    "    city=user_city\n",
    ")\n",
    "\n",
    "if not aqi_data or not hasattr(aqi_data, \"data\"):\n",
    "    print(\"Mumbai with state failed, trying without state...\")\n",
    "    aqi_data = aqi_fetcher.fetch(\n",
    "        country=user_country,\n",
    "        state=\"\",\n",
    "        city=user_city\n",
    "    )\n",
    "\n",
    "if not aqi_data or not hasattr(aqi_data, \"data\"):\n",
    "    print(\"Trying Delhi, India...\")\n",
    "    aqi_data = aqi_fetcher.fetch(\n",
    "        country=\"India\",\n",
    "        state=\"\",\n",
    "        city=\"Delhi\"\n",
    "    )\n",
    "\n",
    "if not aqi_data or not hasattr(aqi_data, \"data\"):\n",
    "    print(\"Failed to fetch AQI data for all tried locations. Please check the URLs manually.\")\n",
    "else:\n",
    "    aqi_data = aqi_data.data  # Convert to dict\n",
    "\n",
    "    prompt = f\"\"\"\n",
    "    You are an expert health advisor using the gpt-5-nano Mini model.\n",
    "\n",
    "    Based on the following air quality conditions in {user_city}, {user_state}, {user_country}:\n",
    "    - Overall AQI: {aqi_data.get('aqi', 'N/A')}\n",
    "    - PM2.5 Level: {aqi_data.get('pm25', 'N/A')} µg/m³\n",
    "    - PM10 Level: {aqi_data.get('pm10', 'N/A')} µg/m³\n",
    "    - CO Level: {aqi_data.get('co', 'N/A')} ppb\n",
    "\n",
    "    Weather conditions:\n",
    "    - Temperature: {aqi_data.get('temperature', 'N/A')}°C\n",
    "    - Humidity: {aqi_data.get('humidity', 'N/A')}%\n",
    "    - Wind Speed: {aqi_data.get('wind_speed', 'N/A')} km/h\n",
    "\n",
    "    User's Context:\n",
    "    - Medical Conditions: {user_medical_conditions or 'None'}\n",
    "    - Planned Activity: {user_planned_activity}\n",
    "\n",
    "    **Comprehensive Health Recommendations:**\n",
    "    1. **Impact of Current Air Quality on Health:**\n",
    "    2. **Necessary Safety Precautions for Planned Activity:**\n",
    "    3. **Advisability of Planned Activity:**\n",
    "    4. **Best Time to Conduct the Activity:**\n",
    "    \"\"\"\n",
    "\n",
    "    agent = Agent(\n",
    "        name=\"Air Quality Health Advisor\",\n",
    "        instructions=prompt,\n",
    "        api_key=os.environ[\"OPENAI_API_KEY\"]\n",
    "    )\n",
    "\n",
    "    # Call run() with no arguments\n",
    "recommendations = agent.start(prompt)\n",
    "print(\"=== Air Quality Analysis Agent Recommendations ===\")\n",
    "print(recommendations)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
